﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace datorgrafik_2
{
    class Camera
    {
        private readonly GameObject objectToFollow;
        private Vector3 _cameraPosition;
        private float frontCamera =- 1f;
        private float sideCamera = 00;
        private float upCamera = 10f;
        private Vector3 _cameraUpVector;

        public Camera(GameObject objectToFollow)
        {
            this.objectToFollow = objectToFollow;
        }

        public void UpdateCamera(ref Matrix view, ref Matrix projection)
        {
            Quaternion objectRotation = objectToFollow.GetRotation();
            Vector3 objectPosition = objectToFollow.GetPosition();

            _cameraPosition = new Vector3(1 * sideCamera, 0.5f * upCamera, 7f * frontCamera);
            _cameraPosition = Vector3.Transform(_cameraPosition, Matrix.CreateFromQuaternion(objectRotation));

            _cameraPosition += objectPosition;

            _cameraUpVector = new Vector3(0, 1, 0);
            _cameraUpVector = Vector3.Transform(_cameraUpVector, Matrix.CreateFromQuaternion(objectRotation));

            view = Matrix.CreateLookAt(_cameraPosition, objectPosition, _cameraUpVector);
        }

        public void IncreaseCamera(float increaseBy)
        {
            upCamera += increaseBy;
        }

        public void DecreaseCamera(float decreaseBy)
        {
            upCamera -= decreaseBy;
        }
    }
}
